package com.android.phoenix.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.phoenix.R;

public class OfflineMapExpListAdapter extends BaseExpandableListAdapter {
	private Context context;
	private LayoutInflater inflater;
	private String[] testProvince;
	private String[] testCitys;

	private GroupHolder groupHolder;
	private ChildHolder childHolder;

	public OfflineMapExpListAdapter(Context context, String[] testProvince,
			String[] testCitys) {
		this.context = context;
		this.testProvince = testProvince;
		this.testCitys = testCitys;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public Object getChild(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return testCitys[childPosition];
	}

	@Override
	public long getChildId(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return childPosition;
	}

	@Override
	public View getGroupView(int groupPosition, boolean isExpanded,
			View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			groupHolder = new GroupHolder();
			convertView = inflater.inflate(R.layout.list_offlinemap_groupitem,
					null);

			groupHolder.tvProvince = (TextView) convertView
					.findViewById(R.id.tvOfflineMapListGroup);
			convertView.setTag(groupHolder);
		} else {
			groupHolder = (GroupHolder) convertView.getTag();
		}
		groupHolder.tvProvince.setText(testProvince[groupPosition]);
		return convertView;
	}

	@Override
	public View getChildView(int groupPosition, int childPosition,
			boolean isLastChild, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			childHolder = new ChildHolder();
			convertView = inflater.inflate(R.layout.list_offlinemap_cityitem,
					null);

			childHolder.tvCity = (TextView) convertView
					.findViewById(R.id.tvOfflineMapCityItem);
			childHolder.tvSize = (TextView) convertView
					.findViewById(R.id.tvOfflineMapSizeItem);
			childHolder.tvInstall = (TextView) convertView
					.findViewById(R.id.tvOfflineMapInstallItem);
			childHolder.imgDownload = (ImageView) convertView
					.findViewById(R.id.imgOfflineMapDownloadItem);
			convertView.setTag(childHolder);
		} else {
			childHolder = (ChildHolder) convertView.getTag();
		}
		childHolder.tvCity.setText(testCitys[childPosition]);
		childHolder.tvSize.setText("34.2MB");
		return convertView;
	}

	@Override
	public int getChildrenCount(int groupPosition) {
		// TODO Auto-generated method stub
		return testCitys.length;
	}

	@Override
	public Object getGroup(int groupPosition) {
		// TODO Auto-generated method stub
		return testProvince.length;
	}

	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub
		return testProvince.length;
	}

	@Override
	public long getGroupId(int groupPosition) {
		// TODO Auto-generated method stub
		return groupPosition;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isChildSelectable(int groupPosition, int childPosition) {
		// TODO Auto-generated method stub
		return true;
	}

	public final class ChildHolder {
		public TextView tvCity;
		public TextView tvSize;
		public TextView tvInstall;
		public ImageView imgDownload;
	}

	public final class GroupHolder {
		TextView tvProvince;
	}
}
